package com.healthdata.service.impl;

import com.healthdata.dao.HospitalByBedSizeMapper;
import com.healthdata.entity.HospitalByBedSize;
import com.healthdata.service.HospitalByBedSizeService;
import com.healthdata.vo.BedOccupancyVO;
import com.healthdata.vo.HospitalTypeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class HospitalByBedSizeServiceImpl implements HospitalByBedSizeService {

    @Autowired
    private HospitalByBedSizeMapper bedSizeMapper;

    private final HospitalByBedSizeMapper hospitalByBedSizeMapper;

    public HospitalByBedSizeServiceImpl(HospitalByBedSizeMapper hospitalByBedSizeMapper) {
        this.hospitalByBedSizeMapper = hospitalByBedSizeMapper;
    }

    @Override
    public List<HospitalByBedSize> getAllBedSizeData() {
        return bedSizeMapper.findAll();
    }

    @Override
    public BedOccupancyVO getBedOccupancyData() {
        BedOccupancyVO vo = new BedOccupancyVO();

        // 获取医院类型
        vo.setHospitalTypes(bedSizeMapper.findHospitalTypes());

        // 获取各床位区间数据
        List<HospitalByBedSize> bedData = bedSizeMapper.findAll();

        vo.setBeds049(new ArrayList<>());
        vo.setBeds5099(new ArrayList<>());
        vo.setBeds100199(new ArrayList<>());
        vo.setBeds200299(new ArrayList<>());
        vo.setBeds300399(new ArrayList<>());
        vo.setBeds400499(new ArrayList<>());

        for (HospitalByBedSize hospital : bedData) {
            vo.getBeds049().add(hospital.getBeds049());
            vo.getBeds5099().add(hospital.getBeds5099());
            vo.getBeds100199().add(hospital.getBeds100199());
            vo.getBeds200299().add(hospital.getBeds200299());
            vo.getBeds300399().add(hospital.getBeds300399());
            vo.getBeds400499().add(hospital.getBeds400499());
        }

        return vo;
    }


    @Override
    public List<HospitalTypeVO> findHospitalTypes() {
        return hospitalByBedSizeMapper.findHospitalTypes();
    }
}